import { message } from 'antd';
import {
  getList,
  getWordDetail,
  getTagList,
  saveWordMark,
  checkWordMark,
  checkQuestionTag,
  selectCheckResultCount,
  checkWordMarkFinal,
} from  '../../../service/api';


export default {
  namespace: 'tag2',
  state: {
    tags: {
      total: 0,
      list: [],
    },
    wordDetail: [],
    checkDetail: [],
    tagList: {
      districtList: [],
      yearCategoryList: [],
      sourceCategoryList: [],
      tixingCategoryList: [],
      recommendCategoryList: [],
      appearCategoryList: [],
      wrongCategoryList: [],
      nianjiCategoryList: [],
      shifhanjiexiCategoryList: [],
      tihaoCategoryList: [],
    },
    treeList: [],
    totalResult: 0,
  },

  effects: {
    *list({ payload }, { call, put }) {
      const response = yield call(getList, payload);
      yield put({
        type: 'r_list',
        payload: response,
      });
    },
    *wordDetail({ payload }, { call, put }) {
      const response = yield call(getWordDetail, payload);
      yield put({
        type: 'r_detail',
        payload: response,
      });
    },
    *tagList({ payload }, { call, put }) {
      const response = yield call(getTagList, payload);
      yield put({
        type: 'r_tag_list',
        payload: response,
      });
    },
    *saveWordMark({ payload }, { call, put }) {
      const response = yield call(saveWordMark, payload);
      yield put({
        type: 'r_save_word_mark',
        payload: response,
      });
    },
    *checkWordMarkList({ payload }, { call, put }) {
      const response = yield call(checkWordMark, payload);
      yield put({
        type: 'r_checkWordMarkList',
        payload: response,
      });
    },
    *checkQuestionTag({ payload }, { call, put }) {
      const response = yield call(checkQuestionTag, payload);
      yield put({
        type: 'r_checkQuestionTag',
        payload: response,
      });
    },
    *selectCheckResultCount({ payload }, { call, put }) {
      const response = yield call(selectCheckResultCount, payload);
      yield put({
        type: 'r_selectCheckResultCount',
        payload: response,
      });
    },
    *checkWordMarkFinal({ payload }, { call, put }) {
      const response = yield call(checkWordMarkFinal, payload);
      yield put({
        type: 'r_checkWordMarkFinal',
        payload: response,
      });
    },
  },

  reducers: {
    r_list(state, action) {
      return {
        ...state,
        tags: action.payload.data,
      };
    },
    r_detail(state, action) {
      return {
        ...state,
        wordDetail: action.payload.data,
      };
    },
    r_tag_list(state, action) {
      return {
        ...state,
        tagList: action.payload.data,
      };
    },
    r_save_word_mark(state, action) {
      if (action.payload.data) {
        message.success('添加成功', 2);
      }
      return {
        ...state,
      };
    },
    r_checkWordMarkList(state, action) {
      return {
        ...state,
        checkDetail: action.payload.data,
      };
    },
    r_checkQuestionTag(state, action) {
      if (action.payload.data) {
        message.success('操作成功', 2);
      }
      return {
        ...state,
      };
    },
    r_selectCheckResultCount(state, action) {
      return {
        ...state,
        totalResult: action.payload.data,
      };
    },
    r_checkWordMarkFinal(state, action) {
      if (action.payload.data) {
        message.success('操作成功', 2);
      }
      return {
        ...state,
      };
    },
  },
};
